<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="文件名称" prop="filename">
        <el-input
          v-model="queryParams.filename"
          placeholder="请输入文件名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核状态" prop="fileVerifyStatus">

        <el-select v-model="queryParams.fileVerifyStatus" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="姓名" prop="username">
        <el-input
          v-model="queryParams.username"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <div style="text-align:right;">
      <el-form-item>

        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>

      </el-form-item>
      </div>
    </el-form>

    <el-row :gutter="10" class="mb8">
     <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['gs:verify:add']"
        >PDF上传</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handlepicAdd"
          v-hasPermi="['gs:verify:add']"
        >图片上传</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['gs:verify:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['gs:verify:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="verifyList" border @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="index" label="序号"  width="55" :index="indexMethod" align="center"/>
     <!-- <el-table-column label="文件路径" align="center" prop="filepath" />-->
      <el-table-column label="文件名称" align="center" prop="filename" />

      <el-table-column label="文件共享状态" align="center" prop="note4" >
        <template slot-scope="scope">
          <span v-if="scope.row.note4 == 0">未共享</span>
          <span v-if="scope.row.note4 == 1">已共享</span>
        </template>

      </el-table-column>
      <!--<el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="部门ID" align="center" prop="deptId" />-->
      <el-table-column label="姓名" align="center" prop="username" />

      <el-table-column label="创建时间" align="center" prop="createTime" />

    <!--  <el-table-column label="备注" align="center" prop="remark" />-->

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">

          <el-button
            size="mini"
            type="text"

            @click="handleXiang(scope.row)"
            v-hasPermi="['system:verify:edit']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"

            @click="handleUpdate(scope.row)"

            v-if="scope.row.note4 == '0'"
            v-hasPermi="['system:verify:edit']"
          >设置共享</el-button>
         <!-- note4为共享状态-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- PDF发布对话框 -->
    <el-dialog :title="fileadd.title" :visible.sync="fileadd.open" width="1000px" append-to-body>
      <el-form ref="form" :model="form"  label-width="100px">
        <el-container>
          <el-header>
            <el-divider content-position="left">
              <p style="color: #00afff; font-size: 20px;">文件上传
              </p>
            </el-divider>
          </el-header>
          <el-main>
            <el-row>
              <el-col span="12">

                <el-form-item label="资料" prop="note1">
                  <file-upload   v-model="form.note1"/>
                </el-form-item>
              </el-col>
              <!--<el-col span="12">
                <el-form-item label="图片" prop="note2">
                  <image-upload :action="imgUpload.url" v-model="form.note2"/>

                </el-form-item>
              </el-col>-->
            </el-row>


          </el-main>
        </el-container>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="filesubmitForm">确 定</el-button>
        <el-button @click="filecancel">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 图片发布对话框 -->
    <el-dialog :title="picfileadd.title" :visible.sync="picfileadd.open" width="1000px" append-to-body>
      <el-form ref="form" :model="form"  label-width="100px">
        <el-container>
          <el-header>
            <el-divider content-position="left">
              <p style="color: #00afff; font-size: 20px;">文件上传
              </p>
            </el-divider>
          </el-header>
          <el-main>
            <el-row>
              <!--<el-col span="12">

                <el-form-item label="资料" prop="note1">
                  <file-upload   v-model="form.note1"/>
                </el-form-item>
              </el-col>-->
              <el-col span="12">
                <el-form-item label="图片" prop="note2">
                  <image-upload  :limit="1" v-model="form.note2"/>

                </el-form-item>
              </el-col>
            </el-row>


          </el-main>
        </el-container>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="picfilesubmitForm">确 定</el-button>
        <el-button @click="picfilecancel">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 添加或修改文件审核对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="共享状态" prop="note4" >

          <el-select v-model="form.note4" placeholder="请选择" >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">

            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" >确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>



    <!-- 详情对话框 -->
    <el-dialog :title="xiang.title" :visible.sync="xiang.open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="300px">



<!--
        <el-image   v-if="form.note3 != null" :src="'http://127.0.0.1:9900/zhxxzhadmin'+form.note3" class="imgpre"></el-image>
-->

        <iframe
          v-if="form.note2 != null"

          :src="'http://127.0.0.1:9900/yhdemoadmin'+form.note2+'#toolbar=0'"
          class="ifr"> </iframe>



      </el-form>
      <div slot="footer" class="dialog-footer">

        <el-button @click="cancela">返回</el-button>
      </div>
    </el-dialog>

  </div>
</template>
<style>
  .img-box1 {
    white-space: pre-wrap;
    width: 90%;

    position: center;
    margin:20px auto;
  }
  .img-box1 img {
    width: 70%;

    position: relative;
    left: 50%;
    transform: translateX(-50%);
  }
  .imgpre{
    width:500px;
    height: 300px;
    osition: relative;
    left: 50%;
    transform: translateX(-50% );

  }
  .ifr{
    width: 70%;
    height: 500px;

    position: relative;
    left: 50%;
    transform: translateX(-50% );
  }
</style>
<script>
import { listVerify, getVerify, delVerify, addVerify, updateVerify,fileUpdate,picfileUpdate,updateshare } from "@/api/module/gs/verify/verify";

export default {
  name: "Verify",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      fileadd:{
        // 是否显示弹出层（用户查询）
        open: false,
        // 弹出层标题（用户查询）
        title: "",
      },
      picfileadd:{
        // 是否显示弹出层（用户查询）
        open: false,
        // 弹出层标题（用户查询）
        title: "",
      },
      imgUpload: {
        // 图片上传的方法地址:
        url: process.env.VUE_APP_BASE_API + "/common/upload",
      },
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 文件审核表格数据
      verifyList: [],
      options: [{
        value: '0',
        label: '未共享'
      }, {
        value: '1',
        label: '已共享'
      }],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        filepath: null,
        filename: null,
        chunkNumber: null,
        chunkSize: null,
        relativePath: null,
        totalChunks: null,
        totalSize: null,
        currentChunkSize: null,
        identifier: null,
        fileVerifyStatus: null,
        userId: null,
        deptId: null,
        username: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null,
        orderByColumn:"note4"

      },
      // 表单参数
      form: {note3:"",
      note2:"",
        },
      fileform: {    note1: null,
        note2: null},
      // 政委审核查询参数
      xiang:{
        // 是否显示弹出层（用户查询）
        open: false,
        // 弹出层标题（用户查询）
        title: "",
      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    indexMethod(index) {
      index = (index + 1) + (this.queryParams.pageNum - 1) * this.queryParams.pageSize
      return index
    },
    /** 查询文件审核列表 */
    getList() {
      this.loading = true;
      listVerify(this.queryParams).then(response => {
        this.verifyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },



    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮
    filecancel() {
      this.fileadd.open = false;
      this.reset();
    },
    // 取消按钮
    picfilecancel() {
      this.picfileadd.open = false;
      this.reset();
    },
    // 取消按钮
    cancela() {
      this.xiang.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        filepath: null,
        filename: null,
        chunkNumber: null,
        chunkSize: null,
        relativePath: null,
        totalChunks: null,
        totalSize: null,
        currentChunkSize: null,
        identifier: null,
        fileVerifyStatus: null,
        userId: null,
        deptId: null,
        username: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.fileadd.open = true;
      this.fileadd.title = "PDF上传";
    },
    /** 新增按钮操作 */
    handlepicAdd() {
      this.reset();
      this.picfileadd.open = true;
      this.picfileadd.title = "图片上传";
    },
    /** PDF文件提交按钮 */
    filesubmitForm() {


      this.$refs["form"].validate(valid => {
        if (valid) {
          fileUpdate(this.form).then(response => {
            this.$modal.msgSuccess("上传成功");
            this.fileadd.open = false;
            this.getList();

          });
        }
        });

    },
    /** 图片文件提交按钮 */
    picfilesubmitForm() {


      this.$refs["form"].validate(valid => {
        if (valid) {
          picfileUpdate(this.form).then(response => {
            this.$modal.msgSuccess("上传成功");
            this.picfileadd.open = false;
            this.getList();

          });
        }
      });

    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getVerify(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "文件审核";
      });
    },
    /** 修改按钮操作 */
    handleXiang(row) {
      this.reset();
      const id = row.id || this.ids
      getVerify(id).then(response => {
        this.form = response.data;
        this.xiang.open = true;
        this.xiang.title = "文件详情";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null&&this.form.note4 == "1") {
            updateshare(this.form).then(response => {
              this.$modal.msgSuccess("设置共享成功");
              this.open = false;
              this.getList();
            });
          } else {
            this.open = false;
            this.reset();
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除文件审核编号为"' + ids + '"的数据项？').then(function() {
        return delVerify(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('gs/verify/export', {
        ...this.queryParams
      }, `verify_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
